/**
 * 平行底形态**
 * 
 */
create or replace function getstpxd(days int) returns setof record as
$$
declare
rec record;
begin
  for rec in EXECUTE '
	select b."date",b.code,b.macd, 
	s."name",s.industry from basic_data b  left join stocks s  on b.code=s.code 
	where 
	to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days||')
	--and  macd::float8 <0
	--and b."close"*b.volume>200000 --交易量大于2千万
	and s.outstanding*b."close">100
	and strpos(s."name",''ST'')=0
	and 0 > (select zd from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+2||') and code=b.code )
	and 0 > (select macd::float8  from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+2||') and code=b.code )
  	and abs(LEAST("open","close") - (select LEAST("open","close") from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+1||') and code=b.code ))<=0.01
  	and abs(low - (select low from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+1||') and code=b.code ))<=0.01
  	--order by macd::float8
	;
' loop
    return next rec;
  end loop;
return;
end
$$
language 'plpgsql';